
/**		
 * 
 *	uk.co.lmfm.guppy.controller.InitialiseCommand
 *	
 *	@version 1.00 | Jan 12, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.controller 
{
	import uk.co.lmfm.guppy.application.enum.ApplicationConstants;
	import uk.co.lmfm.guppy.model.SettingsProxy;
	import uk.co.lmfm.guppy.model.SVNProxy;
	import uk.co.lmfm.guppy.view.SettingsMediator;

	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	/**
	 * InitialiseCommand
	 */
	public class InitialiseCommand extends SimpleCommand implements ICommand 
	{
		override public function execute(notification : INotification) : void
		{
			super.execute(notification);
			
			sendNotification(ApplicationConstants.POLL_VIEWS_FOR_DEFINITIONS);
			
			var settingsProxy : SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;
			var svnProxy : SVNProxy = facade.retrieveProxy(SVNProxy.NAME) as SVNProxy;
			
			if(!settingsProxy.hasPreferences || !settingsProxy.validateSettings(settingsProxy.readSettings()).valid)
			{
				sendNotification(ApplicationConstants.CHANGE_VIEW, SettingsMediator.NAME);
				sendNotification(ApplicationConstants.AUTO_SETUP_START);
				sendNotification(ApplicationConstants.DISABLE_MENU);
				settingsProxy.autoSetup();
			}
			else
			{
				svnProxy.checkForUpdates();
				sendNotification(ApplicationConstants.SET_LIBRARY_PATH);
			}
		}
	}
}
